home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / LOG.H < prev    next >
C/C++ Source or Header  |  1994-02-19  |  3KB  |  133 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #ifndef _LOG_H
  4. #define _LOG_H
  5.  
  6. #include "board.h"
  7. #include "rmove.h"
  8. #include "search.h"
  9. #include "array.h"
  10. #include <fstream.h>
  11. #include <windows.h>
  12.  
  13. enum { Initial_Log_Size = 100 };  // initial log size
  14.                   // (expandable if necessary)
  15.  
  16. class Log;
  17.  
  18. class Log_Entry
  19. {
  20.      // Maintains info on a move made so far in the game.              
  21.  
  22.      public:
  23.  
  24.      Log_Entry(const ReversibleMove &move,
  25.            const char *move_image);
  26.      // create a log entry. 
  27.      // "move_image" is the string representation of the move.
  28.          
  29.      Log_Entry();
  30.      // create a null log entry.  Used only to initialize storage.
  31.          
  32.      Log_Entry( const Log_Entry &);
  33.      // copy constructor
  34.          
  35.      Log_Entry & operator = (const Log_Entry &);
  36.      // assignment operator
  37.      
  38.      ~Log_Entry();
  39.      
  40.      const ReversibleMove &move() const
  41.      {
  42.           return my_move;
  43.      }
  44.      
  45.      const char *image() const
  46.      {
  47.          return (const char *)my_image;
  48.      }
  49.      
  50.      int operator == ( const Log_Entry &l ) const;
  51.      int operator != ( const Log_Entry &l ) const;
  52.  
  53.      private:
  54.          
  55.      ReversibleMove my_move;
  56.      char *my_image;
  57. };
  58.  
  59. class Log : public Array<Log_Entry>
  60. {
  61.      // maintains a log of moves made in the game so far.  Unlike the
  62.      // Move_Array (see movearr.h), moves are not added and removed
  63.      // during the search process.  The log maintains a size, which
  64.      // is the total number of moves ever added, and a current position,
  65.      // which is normally == to its size, but may be less if the
  66.      // user has "taken back" moves.
  67.  
  68.      public:         
  69.     
  70.      Log();
  71.      // create a log.
  72.          
  73.      virtual ~Log();         
  74.  
  75.      void add_move( Board &board,
  76.                 const ReversibleMove &emove,
  77.             const char *move_image,
  78.             const Search::Statistics *stats,
  79.             const Boolean toFile);
  80.      // Add a move to the log.  If "toFile" is true, also record it
  81.      // in the log file.         
  82.          
  83.      void remove_move();
  84.      // remove the most recently added move to the log.
  85.          
  86.      // Return the number of the last move made.  "Backing up"
  87.      // through the moves changes current w/o changing num_moves.     
  88.      unsigned current() const
  89.      {
  90.          return my_current;
  91.      }
  92.  
  93.      // Return the total number of moves made.
  94.      unsigned num_moves() const
  95.      {
  96.          return size();
  97.      }
  98.      
  99.      // Advance the "current" move by one.
  100.      Boolean back_up();
  101.      
  102.      // Decrement the "current" move pointer.
  103.      Boolean go_forward();
  104.      
  105.      // Reset the "current" position to the start of the game, w/o
  106.      //    altering the file or clearing the log.    
  107.      void reset();
  108.      
  109.      const ReversibleMove &last_move() const;
  110.      // return the last move in the log.  The log must be non-empty.
  111.  
  112.      const ReversibleMove &move( const unsigned n ) const;
  113.      // return the nth move in the log.  0 <= n <= num_moves - 1.
  114.     
  115.      void clear();
  116.      // remove everything from the log
  117.          
  118.      void write_header();
  119.  
  120.      void write(char *);
  121.  
  122.      void write_eol();
  123.          
  124. private:
  125.      void flush();
  126.      unsigned my_current;
  127.      ofstream log_file;     
  128.      char buf[100];
  129. };
  130.  
  131. #endif
  132.  
  133.